package com.meirengu.webview.service.impl;

import com.meirengu.service.impl.BaseServiceImpl;
import com.meirengu.utils.DateUtils;
import com.meirengu.webview.model.KwOperationLog;
import com.meirengu.webview.service.KwOperationLogService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * KwOperationLog服务实现层
 *
 * @author Mao
 * @create Tue Apr 17 10:58:14 CST 2018
 */
@Service
public class KwOperationLogServiceImpl extends BaseServiceImpl<KwOperationLog> implements KwOperationLogService {

    public int addOperationLog(String categoryCode, String categoryName, String channelCode,
                               String channelName, String startTime, String endTime,
                               String dataTabel, Integer dataNum, String dataCode,
                               String dataMessage, String remark) throws Exception {

        /*幂等性判断*/
        Map<String, Object> param = new HashMap<>();
        param.put("channelCode", channelCode);
        param.put("channelName", channelName);
        param.put("startTime", startTime);
        param.put("endTime", endTime);
        param.put("dataTabel", dataTabel);
        param.put("dataNum", dataNum);
        List<Map<String, Object>> list = getList(param);
        if (list != null && list.size() > 0) {
            throw new Exception("已有该操作");
        }
        KwOperationLog kwOperationLog = new KwOperationLog();
        kwOperationLog.setCategoryCode(categoryCode);
        kwOperationLog.setCategoryName(categoryName);
        kwOperationLog.setChannelCode(channelCode);
        kwOperationLog.setChannelName(channelName);
        kwOperationLog.setStartTime(DateUtils.strToDate(startTime, "yyyy-MM-dd HH:mm:ss"));
        kwOperationLog.setEndTime(DateUtils.strToDate(endTime, "yyyy-MM-dd HH:mm:ss"));
        kwOperationLog.setDataTabel(dataTabel);
        kwOperationLog.setDataNum(dataNum);
        kwOperationLog.setDataCode(dataCode);
        kwOperationLog.setDataMessage(dataMessage);
        kwOperationLog.setRemark(remark);
        return insert(kwOperationLog);
    }

}
